package com.yellow.userservice.factory;

import com.yellow.userservice.service.LoginServiceImpl.CodeLoginService;
import com.yellow.userservice.service.LoginService;
import com.yellow.userservice.service.LoginServiceImpl.PasswordLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @author: hy
 * @create: 2024-03-23
 */
@Component
public class LoginServiceFactory {

    @Autowired
    private ApplicationContext context;
    public LoginService getLoginService(String type) {
        if ("password".equals(type)) {
            return context.getBean(PasswordLoginService.class);
        } else if ("code".equals(type)) {
            return context.getBean(CodeLoginService.class);
        } else {
            throw new IllegalArgumentException("Unsupported userservice type: " + type);
        }
    }
}
